<!DOCTYPE html>
<html lang="zh-CN">





<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/blog/img/favicon.png">
  <link rel="icon" type="image/png" href="/blog/img/favicon.png">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
    <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
  
  <meta name="theme-color" content="#35495e">
  <meta name="description" content="小菜头的博客，主要记录学习笔记，包含：html,css,javascript,jQuery,vue等">
  <meta name="author" content="A-cai">
  <meta name="keywords" content="html,css,javascript,jQuery,vue">
  <title>20个常用css技巧 - A-cai的blog</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/blog/lib/hint/hint.min.css" />

  
    <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/atom-one-dark.min.css" />
  

  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_yg9cfy8wd6.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_pjno9b9zyxs.css">


<link  rel="stylesheet" href="/blog/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script  src="/blog/js/utils.js" ></script>
<meta name="generator" content="Hexo 4.2.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/blog/">&nbsp;<strong>A-cai的学习笔记</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner intro-2" id="background" parallax=true
         style="background: url('/blog/img/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container text-center white-text fade-in-up">
            <span class="h2" id="subtitle">
              
            </span>

            
              
  <div class="mt-3 post-meta">
    <i class="iconfont icon-date-fill" aria-hidden="true"></i>
    <time datetime="2020-06-26 13:59">
      2020年6月26日 下午
    </time>
  </div>


<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      1.6k 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      23
       分钟
    </span>
  

  
  
    
      <!-- 不蒜子统计文章PV -->
      <span id="busuanzi_container_page_pv" style="display: none">
        <i class="iconfont icon-eye" aria-hidden="true"></i>
        <span id="busuanzi_value_page_pv"></span> 次
      </span>
    
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <div class="post-content mx-auto" id="post">
            
              <p class="note note-info">
                
                  本文最后更新于：2020年3月29日 晚上
                
              </p>
            
            <article class="markdown-body">
              <p><img src="https://imgkr.cn-bj.ufileos.com/9ffcf41b-364f-4a57-975e-d4c81356e3bf.png" srcset="/blog/img/loading.gif" alt=""></p>
<h4 id="©design-by-HeyRain"><a href="#©design-by-HeyRain" class="headerlink" title="©design by HeyRain"></a>©design by HeyRain</h4><h2 id="1、声明"><a href="#1、声明" class="headerlink" title="1、声明"></a>1、声明</h2><p><strong>本文仅为转发学习使用，若侵犯到您的权益，请联系我立即删除！</strong></p>
<blockquote>
<p>原文链接：<a href="http://www.phpxs.com/code/1009945/" target="_blank" rel="noopener">http://www.phpxs.com/code/1009945/</a></p>
</blockquote>
<h2 id="黑白图像"><a href="#黑白图像" class="headerlink" title="黑白图像"></a>黑白图像</h2><p>这段代码会让你的彩色照片显示为黑白照片，是不是很酷？</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">img</span><span class="hljs-selector-class">.desaturate</span> &#123;
    <span class="hljs-attribute">filter</span>: <span class="hljs-built_in">grayscale</span>(<span class="hljs-number">100%</span>);
    <span class="hljs-attribute">-webkit-filter</span>: <span class="hljs-built_in">grayscale</span>(<span class="hljs-number">100%</span>);
    <span class="hljs-attribute">-moz-filter</span>: <span class="hljs-built_in">grayscale</span>(<span class="hljs-number">100%</span>);
    <span class="hljs-attribute">-ms-filter</span>: <span class="hljs-built_in">grayscale</span>(<span class="hljs-number">100%</span>);
    <span class="hljs-attribute">-o-filter</span>: <span class="hljs-built_in">grayscale</span>(<span class="hljs-number">100%</span>);
&#125;</code></pre></div>

<h2 id="2、使用-not-在菜单上应用-取消应用边框"><a href="#2、使用-not-在菜单上应用-取消应用边框" class="headerlink" title="2、使用:not()在菜单上应用/取消应用边框"></a>2、使用:not()在菜单上应用/取消应用边框</h2><p>先给每一个菜单项添加边框</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-comment">/* add border */</span>
<span class="hljs-selector-class">.nav</span> <span class="hljs-selector-tag">li</span> &#123;
    <span class="hljs-attribute">border-right</span>: <span class="hljs-number">1px</span> solid <span class="hljs-number">#666</span>;
&#125;</code></pre></div>

<p>然后再除去最后一个元素</p>
<div class="hljs"><pre><code class="hljs css">// remove border /
<span class="hljs-selector-class">.nav</span> <span class="hljs-selector-tag">li</span><span class="hljs-selector-pseudo">:last-child</span> &#123;
    <span class="hljs-attribute">border-right</span>: none;
&#125;</code></pre></div>

<p>可以直接使用 :not() 伪类来应用元素：</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.nav</span> <span class="hljs-selector-tag">li</span><span class="hljs-selector-pseudo">:not(</span><span class="hljs-selector-pseudo">:last-child)</span> &#123;
    <span class="hljs-attribute">border-right</span>: <span class="hljs-number">1px</span> solid <span class="hljs-number">#666</span>;
&#125;</code></pre></div>

<p>这样代码就干净，易读，易于理解了。</p>
<p>当然，如果你的新元素有兄弟元素的话，也可以使用通用的兄弟选择符（~）：</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-class">.nav</span> <span class="hljs-selector-tag">li</span><span class="hljs-selector-pseudo">:first-child</span>~<span class="hljs-selector-tag">li</span> &#123;
    <span class="hljs-attribute">border-left</span>: <span class="hljs-number">1px</span> solid <span class="hljs-number">#666</span>;
&#125;</code></pre></div>

<h2 id="3、页面顶部阴影"><a href="#3、页面顶部阴影" class="headerlink" title="3、页面顶部阴影"></a>3、页面顶部阴影</h2><p>下面这个简单的 css 代码片段可以给网页加上漂亮的顶部阴影效果：</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">body</span><span class="hljs-selector-pseudo">:before</span> &#123;
    <span class="hljs-attribute">content</span>: <span class="hljs-string">""</span>;
    <span class="hljs-attribute">position</span>: fixed;
    <span class="hljs-attribute">top</span>: -<span class="hljs-number">10px</span>;
    <span class="hljs-attribute">left</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">10px</span>;
    <span class="hljs-attribute">-webkit-box-shadow</span>: <span class="hljs-number">0px</span> <span class="hljs-number">0px</span> <span class="hljs-number">10px</span> <span class="hljs-built_in">rgba</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, .<span class="hljs-number">8</span>);
    <span class="hljs-attribute">-moz-box-shadow</span>: <span class="hljs-number">0px</span> <span class="hljs-number">0px</span> <span class="hljs-number">10px</span> <span class="hljs-built_in">rgba</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, .<span class="hljs-number">8</span>);
    <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">0px</span> <span class="hljs-number">0px</span> <span class="hljs-number">10px</span> <span class="hljs-built_in">rgba</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, .<span class="hljs-number">8</span>);
    <span class="hljs-attribute">z-index</span>: <span class="hljs-number">100</span>;
&#125;</code></pre></div>

<h2 id="4、给-body-添加行高"><a href="#4、给-body-添加行高" class="headerlink" title="4、给 body 添加行高"></a>4、给 body 添加行高</h2><p>你不需要分别添加 line-height 到每个 p,h 标记等。只要添加到 body 即可：</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">body</span> &#123;
    <span class="hljs-attribute">line-height</span>: <span class="hljs-number">1</span>;
&#125;</code></pre></div>

<p>这样文本元素就可以很容易地从 body 继承。</p>
<p>这样文本元素就可以很容易地从 body 继承。</p>
<h2 id="5、所有一切都垂直居中"><a href="#5、所有一切都垂直居中" class="headerlink" title="5、所有一切都垂直居中"></a>5、所有一切都垂直居中</h2><p>要将所有元素垂直居中，太简单了：</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">html</span>,
<span class="hljs-selector-tag">body</span> &#123;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">100%</span>;
    <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
&#125;

<span class="hljs-selector-tag">body</span> &#123;
    <span class="hljs-attribute">-webkit-align-items</span>: center;
    <span class="hljs-attribute">-ms-flex-align</span>: center;
    <span class="hljs-attribute">align-items</span>: center;
    <span class="hljs-attribute">display</span>: -webkit-flex;
    <span class="hljs-attribute">display</span>: flex;
&#125;</code></pre></div>

<p>看，是不是很简单。注意：在 IE11 中要小心 flexbox。</p>
<h2 id="6、逗号分隔的列表"><a href="#6、逗号分隔的列表" class="headerlink" title="6、逗号分隔的列表"></a>6、逗号分隔的列表</h2><p>让 html 列表项看上去像一个真正的，用逗号分隔的列表：</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">ul</span>&gt;<span class="hljs-selector-tag">li</span><span class="hljs-selector-pseudo">:not(</span><span class="hljs-selector-pseudo">:last-child)</span><span class="hljs-selector-pseudo">::after</span> &#123;
    <span class="hljs-attribute">content</span>: <span class="hljs-string">","</span>;
&#125;</code></pre></div>

<p>对最后一个列表项使用:not()伪类。</p>
<p>对最后一个列表项使用:not()伪类。</p>
<h2 id="7-使用负的-nth-child-选择项目"><a href="#7-使用负的-nth-child-选择项目" class="headerlink" title="7 使用负的 nth-child 选择项目"></a>7 使用负的 nth-child 选择项目</h2><p>在 CSS 中使用负的 nth-child 选择项目 1 到项目 n。</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">li</span> &#123;
    <span class="hljs-attribute">display</span>: none;
&#125;

<span class="hljs-comment">/*select items through and display them*/</span>
<span class="hljs-selector-tag">li</span><span class="hljs-selector-pseudo">:nth-child(-n+3)</span> &#123;
    <span class="hljs-attribute">display</span>: block;
&#125;</code></pre></div>

<h2 id="8、对图标使用-SVG"><a href="#8、对图标使用-SVG" class="headerlink" title="8、对图标使用 SVG"></a>8、对图标使用 SVG</h2><p>我们没有理由不对图标使用 SVG：</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">logo</span> &#123;
    <span class="hljs-attribute">background</span>: <span class="hljs-built_in">url</span>(<span class="hljs-string">"logo.svg"</span>);
&#125;</code></pre></div>

<p>SVG 对所有的分辨率类型都具有良好的扩展性，并支持所有浏览器都回归到 IE9。这样可以避开.png、.jpg 或.gif 文件了。</p>
<p>SVG 对所有的分辨率类型都具有良好的扩展性，并支持所有浏览器都回归到 IE9。这样可以避开.png、.jpg 或.gif 文件了。</p>
<h2 id="9、优化显示文本"><a href="#9、优化显示文本" class="headerlink" title="9、优化显示文本"></a>9、优化显示文本</h2><p>有时，字体并不能在所有设备上都达到最佳的显示，所以可以让设备浏览器来帮助你：</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">html</span> &#123;
    <span class="hljs-attribute">-moz-osx-font-smoothing</span>: grayscale;
    <span class="hljs-attribute">-webkit-font-smoothing</span>: antialiased;
    <span class="hljs-attribute">text-rendering</span>: optimizeLegibility;
&#125;</code></pre></div>

<p>注：请负责任地使用 optimizeLegibility。此外，IE/Edge 没有 text-rendering 支持。</p>
<p>注：请负责任地使用 optimizeLegibility。此外，IE/Edge 没有 text-rendering 支持。</p>
<h2 id="10、对纯-CSS-滑块使用-max-height"><a href="#10、对纯-CSS-滑块使用-max-height" class="headerlink" title="10、对纯 CSS 滑块使用 max-height"></a>10、对纯 CSS 滑块使用 max-height</h2><p>使用 max-height 和溢出隐藏来实现只有 CSS 的滑块：</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">slider</span> <span class="hljs-selector-tag">ul</span> &#123;
    <span class="hljs-attribute">max-height</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">overflow</span>: hidden;
&#125;

<span class="hljs-selector-tag">slider</span><span class="hljs-selector-pseudo">:hover</span> <span class="hljs-selector-tag">ul</span> &#123;
    <span class="hljs-attribute">max-height</span>: <span class="hljs-number">1000px</span>;
    <span class="hljs-attribute">transition</span>: .<span class="hljs-number">3s</span> ease;
&#125;</code></pre></div>

<h2 id="11、继承-box-sizing"><a href="#11、继承-box-sizing" class="headerlink" title="11、继承 box-sizing"></a>11、继承 box-sizing</h2><p>让 box-sizing 继承 html：</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">html</span> &#123;
    <span class="hljs-attribute">box-sizing</span>: border-box;
&#125;

*,
*<span class="hljs-selector-pseudo">:before</span>,
*<span class="hljs-selector-pseudo">:after</span> &#123;
    <span class="hljs-attribute">box-sizing</span>: inherit;
&#125;</code></pre></div>

<p>这样在插件或杠杆其他行为的其他组件中就能更容易地改变 box-sizing 了。</p>
<p>这样在插件或杠杆其他行为的其他组件中就能更容易地改变 box-sizing 了。</p>
<h2 id="12、表格单元格等宽"><a href="#12、表格单元格等宽" class="headerlink" title="12、表格单元格等宽"></a>12、表格单元格等宽</h2><p>表格工作起来很麻烦，所以务必尽量使用 table-layout:fixed 来保持单元格的等宽：</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">calendar</span> &#123;
    <span class="hljs-attribute">table-layout</span>: fixed;
&#125;</code></pre></div>

<h2 id="13、用-Flexbox-摆脱外边距的各种-hack"><a href="#13、用-Flexbox-摆脱外边距的各种-hack" class="headerlink" title="13、用 Flexbox 摆脱外边距的各种 hack"></a>13、用 Flexbox 摆脱外边距的各种 hack</h2><p>当需要用到列分隔符时，通过 flexbox 的 space-between 属性，你就可以摆脱 nth-，first-，和 last-child 的 hack 了：</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">list</span> &#123;
    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">justify-content</span>: space-between;
&#125;

<span class="hljs-selector-tag">list</span><span class="hljs-selector-class">.person</span> &#123;
    <span class="hljs-attribute">flex-basis</span>: <span class="hljs-number">23%</span>;
&#125;</code></pre></div>

<p>现在，列表分隔符就会在均匀间隔的位置出现。</p>
<h2 id="14、使用属性选择器用于空链接"><a href="#14、使用属性选择器用于空链接" class="headerlink" title="14、使用属性选择器用于空链接"></a>14、使用属性选择器用于空链接</h2><p>当 a 元素没有文本值，但 href 属性有链接的时候显示链接：</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">a</span><span class="hljs-selector-attr">[href^=<span class="hljs-string">"http"</span>]</span><span class="hljs-selector-pseudo">:empty</span><span class="hljs-selector-pseudo">::before</span> &#123;
    <span class="hljs-attribute">content</span>: <span class="hljs-built_in">attr</span>(href);
&#125;</code></pre></div>

<p>相当方便。</p>
<h2 id="15、检测鼠标双击"><a href="#15、检测鼠标双击" class="headerlink" title="15、检测鼠标双击"></a>15、检测鼠标双击</h2><p>HTML：CSS：</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">test</span> <span class="hljs-selector-tag">span</span>  &#123;
    <span class="hljs-attribute">position</span>: relative;
&#125;

<span class="hljs-selector-tag">test</span> <span class="hljs-selector-tag">span</span> <span class="hljs-selector-tag">a</span> &#123;
    <span class="hljs-attribute">position</span>: relative;
    <span class="hljs-attribute">z-index</span>: <span class="hljs-number">2</span>;
&#125;

<span class="hljs-selector-tag">test</span> <span class="hljs-selector-tag">span</span> <span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:hover</span>,
<span class="hljs-selector-class">.test</span> <span class="hljs-selector-tag">span</span> <span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:active</span> &#123;
    <span class="hljs-attribute">z-index</span>: <span class="hljs-number">4</span>;
&#125;

<span class="hljs-selector-tag">test</span> <span class="hljs-selector-tag">span</span> <span class="hljs-selector-tag">input</span> &#123;
    <span class="hljs-attribute">background</span>: transparent;
    <span class="hljs-attribute">border</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">cursor</span>: pointer;
    <span class="hljs-attribute">position</span>: absolute;
    <span class="hljs-attribute">top</span>: -<span class="hljs-number">1px</span>;
    <span class="hljs-attribute">left</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">101%</span>;
    <span class="hljs-comment">/*Hacky*/</span>
    <span class="hljs-attribute">height</span>: <span class="hljs-number">301%</span>;
    <span class="hljs-comment">/*Hacky*/</span>
    20.z-index: 3;
&#125;

<span class="hljs-selector-tag">test</span> <span class="hljs-selector-tag">span</span> <span class="hljs-selector-tag">input</span><span class="hljs-selector-pseudo">:focus</span> &#123;
    <span class="hljs-attribute">background</span>: transparent;
    <span class="hljs-attribute">border</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">z-index</span>: <span class="hljs-number">1</span>;
&#125;</code></pre></div>

<h2 id="16、CSS-写出三角形"><a href="#16、CSS-写出三角形" class="headerlink" title="16、CSS 写出三角形"></a>16、CSS 写出三角形</h2><p>利用 border 来写三角形代码，并且兼容 IE6.</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-comment">/* create an arrow that points up */</span>
<span class="hljs-selector-tag">div</span><span class="hljs-selector-class">.arrow-up</span> &#123;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">0px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">0px</span>;
    <span class="hljs-attribute">border-left</span>: <span class="hljs-number">5px</span> solid transparent;
    <span class="hljs-comment">/* left arrow slant */</span>
    <span class="hljs-attribute">border-right</span>: <span class="hljs-number">5px</span> solid transparent;
    <span class="hljs-comment">/* right arrow slant */</span>
    <span class="hljs-attribute">border-bottom</span>: <span class="hljs-number">5px</span> solid <span class="hljs-number">#2f2f2f</span>;
    <span class="hljs-comment">/* bottom, add background color here */</span>
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">0px</span>;
    <span class="hljs-attribute">line-height</span>: <span class="hljs-number">0px</span>;
&#125;

<span class="hljs-comment">/* create an arrow that points down */</span>
<span class="hljs-selector-tag">div</span><span class="hljs-selector-class">.arrow-down</span> &#123;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">0px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">0px</span>;
    <span class="hljs-attribute">border-left</span>: <span class="hljs-number">5px</span> solid transparent;
    <span class="hljs-attribute">border-right</span>: <span class="hljs-number">5px</span> solid transparent;
    <span class="hljs-attribute">border-top</span>: <span class="hljs-number">5px</span> solid <span class="hljs-number">#2f2f2f</span>;
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">0px</span>;
    <span class="hljs-attribute">line-height</span>: <span class="hljs-number">0px</span>;
&#125;

<span class="hljs-comment">/* create an arrow that points left */</span>
<span class="hljs-selector-tag">div</span><span class="hljs-selector-class">.arrow-left</span> &#123;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">0px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">0px</span>;
    <span class="hljs-attribute">border-bottom</span>: <span class="hljs-number">5px</span> solid transparent;
    <span class="hljs-comment">/* left arrow slant */</span>
    <span class="hljs-attribute">border-top</span>: <span class="hljs-number">5px</span> solid transparent;
    <span class="hljs-comment">/* right arrow slant */</span>
    <span class="hljs-attribute">border-right</span>: <span class="hljs-number">5px</span> solid <span class="hljs-number">#2f2f2f</span>;
    <span class="hljs-comment">/* bottom, add background color here */</span>
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">0px</span>;
    <span class="hljs-attribute">line-height</span>: <span class="hljs-number">0px</span>;
&#125;

<span class="hljs-comment">/* create an arrow that points right */</span>
<span class="hljs-selector-tag">div</span><span class="hljs-selector-class">.arrow-right</span> &#123;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">0px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">0px</span>;
    <span class="hljs-attribute">border-bottom</span>: <span class="hljs-number">5px</span> solid transparent;
    <span class="hljs-comment">/* left arrow slant */</span>
    <span class="hljs-attribute">border-top</span>: <span class="hljs-number">5px</span> solid transparent;
    <span class="hljs-comment">/* right arrow slant */</span>
    <span class="hljs-attribute">border-left</span>: <span class="hljs-number">5px</span> solid <span class="hljs-number">#2f2f2f</span>;
    <span class="hljs-comment">/* bottom, add background color here */</span>
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">0px</span>;
    <span class="hljs-attribute">line-height</span>: <span class="hljs-number">0px</span>;
&#125;</code></pre></div>

<h2 id="17、CSScalc-的使用"><a href="#17、CSScalc-的使用" class="headerlink" title="17、CSScalc()的使用"></a>17、CSScalc()的使用</h2><p>calc()用法类似于函数，能够给元素设置动态的值：</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-comment">/* basic calc */</span>
<span class="hljs-selector-class">.simpleBlock</span> &#123;
    <span class="hljs-attribute">width</span>: <span class="hljs-built_in">calc</span>(<span class="hljs-number">100%</span> - <span class="hljs-number">100px</span>);
&#125;
<span class="hljs-comment">/* calc in calc */</span>
<span class="hljs-selector-class">.complexBlock</span> &#123;
    <span class="hljs-attribute">width</span>: <span class="hljs-built_in">calc</span>(<span class="hljs-number">100%</span> - <span class="hljs-number">50%</span> / <span class="hljs-number">3</span>);
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">5px</span> <span class="hljs-built_in">calc</span>(<span class="hljs-number">3%</span> - <span class="hljs-number">2px</span>);
    <span class="hljs-attribute">margin-left</span>: <span class="hljs-built_in">calc</span>(<span class="hljs-number">10%</span> + <span class="hljs-number">10px</span>);
&#125;</code></pre></div>

<h2 id="18、文本渐变"><a href="#18、文本渐变" class="headerlink" title="18、文本渐变"></a>18、文本渐变</h2><p>文本渐变效果很流行，使用 CSS 能够很简单就实现：</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">h2</span><span class="hljs-selector-attr">[data-text]</span> &#123;
    <span class="hljs-attribute">position</span>: relative;
&#125;

<span class="hljs-selector-tag">h2</span><span class="hljs-selector-attr">[data-text]</span><span class="hljs-selector-pseudo">::after</span> &#123;
    <span class="hljs-attribute">content</span>: <span class="hljs-built_in">attr</span>(data-text);
    <span class="hljs-attribute">z-index</span>: <span class="hljs-number">10</span>;
    <span class="hljs-attribute">color</span>: <span class="hljs-number">#e3e3e3</span>;
    <span class="hljs-attribute">position</span>: absolute;
    <span class="hljs-attribute">top</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">left</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">-webkit-mask-image</span>: <span class="hljs-built_in">-webkit-gradient</span>(linear, left top, left bottom, from(rgba(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>)), <span class="hljs-built_in">color-stop</span>(<span class="hljs-number">50%</span>, rgba(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>)), <span class="hljs-built_in">to</span>(rgba(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>)));
&#125;</code></pre></div>

<h2 id="19、禁用鼠标事件"><a href="#19、禁用鼠标事件" class="headerlink" title="19、禁用鼠标事件"></a>19、禁用鼠标事件</h2><p>CSS 新增的 pointer-events 让你能够禁用元素的鼠标事件，例如，一个连接如果设置了下面的样式就无法点击了。</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">disabled</span> &#123;
    <span class="hljs-attribute">pointer-events</span>: none;
&#125;</code></pre></div>

<h2 id="20、模糊文本"><a href="#20、模糊文本" class="headerlink" title="20、模糊文本"></a>20、模糊文本</h2><p>简单但很漂亮的文本模糊效果，简单又好看！</p>
<div class="hljs"><pre><code class="hljs css"><span class="hljs-selector-tag">blur</span> &#123;
    <span class="hljs-attribute">color</span>: transparent;
    <span class="hljs-attribute">text-shadow</span>: <span class="hljs-number">0</span> <span class="hljs-number">0</span> <span class="hljs-number">5px</span> <span class="hljs-built_in">rgba</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0.5</span>);
&#125;</code></pre></div>

<h2 id="关于我"><a href="#关于我" class="headerlink" title="关于我"></a>关于我</h2><p><img src="https://imgkr.cn-bj.ufileos.com/7a11c0af-72a0-452a-92f6-bcf980d3b1d3.png" srcset="/blog/img/loading.gif" alt=""></p>

            </article>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                
              </div>
              
                <p class="note note-warning">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" target="_blank" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！</p>
              
              
                <div class="post-prevnext row">
                  <div class="post-prev col-6">
                    
                    
                      <a href="/blog/2020/06/26/%E5%9E%82%E7%9B%B4%E5%B1%85%E4%B8%AD%E7%9A%84%E6%96%B9%E6%B3%95/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">垂直居中的方法</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </div>
                  <div class="post-next col-6">
                    
                    
                      <a href="/blog/2020/06/26/%E6%BB%9A%E5%8A%A8%E6%9D%A1MDN%E5%8F%82%E8%80%83%E6%96%87%E6%A1%A3/">
                        <span class="hidden-mobile">滚动条MDN参考文档</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </div>
                </div>
              
            </div>

            
              <!-- Comments -->
              <div class="comments" id="comments">
                
                

              </div>
            
          </div>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div id="tocbot"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  

  <footer class="mt-5">
  <div class="text-center py-3">
    <div>
      <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a>
      <i class="iconfont icon-love"></i>
      <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener">
        <span>Fluid</span></a>
    </div>
    

    

    
  </div>
</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/blog/js/debouncer.js" ></script>
<script  src="/blog/js/main.js" ></script>

<!-- Plugins -->


  
    <script  src="/blog/js/lazyload.js" ></script>
  



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/blog/js/clipboard-use.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: 'article.markdown-body',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "20个常用css技巧&nbsp;",
      ],
      cursorChar: "|",
      typeSpeed: 70,
      loop: true,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "hover",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/blog/js/local-search.js" ></script>
  <script>
    var path = "/blog/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>







  
  
    <script>
      !function (e, t, a) {
        function r() {
          for (var e = 0; e < s.length; e++) s[e].alpha <= 0 ? (t.body.removeChild(s[e].el), s.splice(e, 1)) : (s[e].y--, s[e].scale += .004, s[e].alpha -= .013, s[e].el.style.cssText = "left:" + s[e].x + "px;top:" + s[e].y + "px;opacity:" + s[e].alpha + ";transform:scale(" + s[e].scale + "," + s[e].scale + ") rotate(45deg);background:" + s[e].color + ";z-index:99999");
          requestAnimationFrame(r)
        }

        function n() {
          var t = "function" == typeof e.onclick && e.onclick;
          e.onclick = function (e) {
            t && t(), o(e)
          }
        }

        function o(e) {
          var a = t.createElement("div");
          a.className = "heart", s.push({
            el: a,
            x: e.clientX - 5,
            y: e.clientY - 5,
            scale: 1,
            alpha: 1,
            color: c()
          }), t.body.appendChild(a)
        }

        function i(e) {
          var a = t.createElement("style");
          a.type = "text/css";
          try {
            a.appendChild(t.createTextNode(e))
          } catch (t) {
            a.styleSheet.cssText = e
          }
          t.getElementsByTagName("head")[0].appendChild(a)
        }

        function c() {
          return "rgb(" + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + ")"
        }

        var s = [];
        e.requestAnimationFrame = e.requestAnimationFrame || e.webkitRequestAnimationFrame || e.mozRequestAnimationFrame || e.oRequestAnimationFrame || e.msRequestAnimationFrame || function (e) {
          setTimeout(e, 1e3 / 60)
        }, i(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"), n(), r()
      }(window, document);
    </script>
  













</body>
</html>
